<template>
  <div id="app">
    <header v-if="isAuthenticated">
      <nav>
        <ul class="nav-links">
          <li><router-link to="/">首页</router-link></li>
          <li><router-link to="/public-activities">公开活动列表</router-link></li>
          <li v-if="isAdmin"><router-link to="/activity-management">活动管理</router-link></li>
        </ul>
        <button class="logout-btn" @click="confirmLogout">登出</button>
      </nav>
    </header>
    <main>
      <router-view/>
    </main>
  </div>
</template>

<script>
export default {
  computed: {
    isAuthenticated() {
      return localStorage.getItem('isAuthenticated') === 'true';
    },
    isAdmin() {
      return localStorage.getItem('isAdmin') === 'true';
    }
  },
  methods: {
    confirmLogout() {
      if (confirm('确定要退出登录吗？')) {
        this.logout();
      }
    },
    logout() {
      localStorage.removeItem('isAuthenticated');
      localStorage.removeItem('isAdmin');
      this.$router.push('/login');
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background-color: #42b983;
  color: white;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 1rem;
}

.nav-links li a {
  color: white;
  text-decoration: none;
  font-weight: bold;
  transition: color 0.3s;
}

.nav-links li a:hover {
  color: #2c3e50;
}

.logout-btn {
  background-color: #2c3e50;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.logout-btn:hover {
  background-color: #1a252f;
}

main {
  flex: 1;
  padding: 2rem;
}
</style>
